package com.java.zhuiyun.api.book_mark.mapper;

import com.java.zhuiyun.api.book_mark.entity.BookMark;
import com.java.zhuiyun.api.course_pc.entity.Course;
import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @InterfaceName BookMarkMapper
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/31 10:26
 **/
@Mapper
public interface BookMarkMapper {
    /*
    * @Author wuwan
    * @Description 添加收藏
    * @Date 2023/8/31 10:34
    * @Return
    * @param null
    */
    @Insert("insert into book_mark (user_id,course_id,create_time) values (#{uid},#{cid},#{createTime});")
    Integer addBookMark(Integer uid, Integer cid, Date createTime);
    /*
    * @Author wuwan
    * @Description 查询出用户收藏的课程
    * @Date 2023/8/31 10:34
    * @Return
    * @param null
    */
    @Select("select * from book_mark where user_id = #{uid}")
    List<BookMark> getBookMark(Integer uid);

    @Select("select * from course where id = #{cid} ;")
    Course getCourse(Integer cid);
    /*
    * @Author wuwan
    * @Description 取消个人信息课程收藏
    * @Date 2023/8/31 11:09
    * @Return
    * @param null
    */
    @Delete("delete from book_mark where id = #{id}")
    Integer delBookMark(Integer id);


    /*
     * @Author WX
     * @Description 通过课程id和用户id查询值
     * @Date 2023/8/31 15:07
     * @Return
     * @param null
     */
    @Select("<script> " +
            "SELECT * " +
            "FROM book_mark " +
            "WHERE user_id = #{userId} " +
            "AND course_id IN " +
            "<foreach collection='courseIdList' item='courseId' separator=',' open='(' close=')'>" +
            "#{courseId}" +
            "</foreach> " +
            "</script>")
    List<BookMark> getSeriesCourseByUserId(Integer userId, List<String> courseIdList);

    /*
     * @Author wuwan
     * @Description 取消课程收藏 //王旭专用
     * @Date 2023/8/31 11:09
     * @Return
     * @param null
     */
    @Delete("delete from book_mark where user_id = #{uid} and course_id = #{cid}")
    Integer delBookMarkCourse(Integer uid, Integer cid);
    /*
    * @Author wuwan
    * @Description 是否收藏课程
    * @Date 2023/9/3 20:11
    * @Return 
    * @param null
    */
    @Select("select * from book_mark where user_id=#{uid} and course_id =#{cid}")
    List<BookMark> getUser(Integer uid,Integer cid);
}
